package com.cskaoyan.mall.commons.util.jwt;

import com.alibaba.fastjson.JSON;
import com.cskaoyan.mall.commons.result.UserLoginMsg;
import com.cskaoyan.mall.commons.util.CookieUtil;

import javax.servlet.http.HttpServletRequest;

/**
 * Auth: 杨宇健
 * Time: 2023/1/10 16:35
 * Description: 返回user数据
 **/
public class UserByTokenUtils {
    public static UserLoginMsg getUser(String token){
        String parse = JwtTokenUtils.builder().token(token).build().freeJwt();
        UserLoginMsg user = JSON.parseObject(parse, UserLoginMsg.class);
        return user;
    }

    public static UserLoginMsg getUser(HttpServletRequest request){
        String access_token = CookieUtil.getCookieValue(request, "access_token");
        UserLoginMsg user = getUser(access_token);
        return user;
    }
}
